from data_process.feature_algorithm.DataAlgorithm import DataAlgorithm
from utils.wav_util import *


class MultiDopplerAlgorithm(DataAlgorithm):

    def __init__(self, wavPath, params):
        super(MultiDopplerAlgorithm, self).__init__(params)
        self.wavPath = wavPath

    def createFeature(self):
        feature = self.getSignalGredientFeature()
        return feature

    def getSignalGredientFeature(self):
        wavPath = self.wavPath
        sonicStart = self.params.sonicStart
        sonicInter = self.params.sonicInter
        sonicNum = self.params.sonicNum
        lipOffset = self.params.lipOffset
        nfft = self.params.nfft
        frameTime = self.params.frameTime
        aheadTime = self.params.aheadTime

        feas = []

        fs, signalWav = wav.read(wavPath)
        Zxx = getSTFT(signalWav, fs, nfft, frameTime, aheadTime)
        for sonicFreq in range(sonicStart, sonicStart+sonicInter*(sonicNum), sonicInter):
            # filtWav = filtAndGetTargetWav(signalWav, 3, sonicFreq, lipOffset, fs)
            res = getTargetFeature(Zxx, sonicFreq, lipOffset, fs, nfft)
            res = SubAdjacent(res)
            res = np.abs(res)
            feas.append(res)
        return feas